﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Licenta_Stomatologie.Panels
{
    public partial class Incasari : UserControl
    {
        private String[] appType = new String[] { "Control", "Interventie medicala" };

        public Incasari()
        {
            InitializeComponent();
            getRestante();
            getPrimite();
        }

        private void getRestante()
        {
            ProjectDBEntities db = new ProjectDBEntities();

            IEnumerable<Appointment> apps = db.Appointments.Where(a => a.achitat == 0);

            DataTable dt = new DataTable("Restante");

            DataColumn[] cols = new DataColumn[] { new DataColumn("Pacient",typeof(String)), new DataColumn("Tip vizita",typeof(String)), new DataColumn("Suma",typeof(String)) };

            dt.Columns.AddRange(cols);

            foreach (Appointment app in apps)
            {
                Pacient pac = db.Pacients.First(p => p.id == app.pacientId);

                dt.Rows.Add( pac.nume + " " + pac.prenume, appType[(int) app.type], app.cost );
            }

            dgvToReceive.DataSource = dt;
        }

        private void getPrimite()
        {
            ProjectDBEntities db = new ProjectDBEntities();

            IEnumerable<Appointment> apps = db.Appointments.Where(a => a.achitat == 1 && a.cost != 0);

            DataTable dt = new DataTable("Primite");

            DataColumn[] cols = new DataColumn[] { new DataColumn("Pacient", typeof(String)), new DataColumn("Tip vizita", typeof(String)), new DataColumn("Suma", typeof(String)) };

            dt.Columns.AddRange(cols);

            foreach (Appointment app in apps)
            {
                Pacient pac = db.Pacients.First(p => p.id == app.pacientId);

                dt.Rows.Add(pac.nume + " " + pac.prenume, appType[(int)app.type], app.cost);
            }

            dgvReceived.DataSource = dt;
        }
    }

    
}
